﻿using System;
using System.Collections.Generic;
using Play.Messaging;
using Play.VstPluginManagement;

namespace Play.TrackManagement
{
	public class TrackSession
	{
		private readonly TrackFactory _trackFactory;

		public TrackSession(TrackFactory trackFactory)
		{
			_trackFactory = trackFactory;
		}

		public event MessageEventHandler SendMessage;

		private readonly List<Track> _tracks = new List<Track>();
		public IEnumerable<Track> Tracks { get { return _tracks; } }

		public void HandleMessage(CreateTrackRequestMessage message)
		{
			var track = _trackFactory.CreateTrackFromPluginInfo(message.VstPluginInfo);
			_tracks.Add(track);
			SendMessage(new TrackCreatedMessage(track));
		}
	}
}